const fs = require('fs');
const path = require('path');

const sourceDir = path.resolve(__dirname, 'dist');
const targetDir = path.resolve(__dirname, '../exam-api/src/main/resources/static'); // 替换为你的目标路径

function copyDir(src, dest) {
  const files = fs.readdirSync(src);
  if (!fs.existsSync(dest)) {
    fs.mkdirSync(dest, { recursive: true });
  }

  for (const file of files) {
    const srcFile = path.join(src, file);
    const destFile = path.join(dest, file);

    const stat = fs.statSync(srcFile);
    if (stat.isDirectory()) {
      copyDir(srcFile, destFile);
    } else {
      fs.copyFileSync(srcFile, destFile);
    }
  }
}

copyDir(sourceDir, targetDir);
console.log('Build and deployment completed.');